<?php
namespace app\decorate\model;
use app\BaseModel;
use think\facade\Db;



class AdminColumn extends BaseModel
{
    //定义表名 栏目表
    protected $name = 'longbing_card_decorate_column';

    /**
     * @param $query
     * 查询范围
     */
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }
    /**
     * @param $query
     * 查询范围
     */
    public function scopeId($query, $id){
        $query->where('id', '<>', $id);
    }
    /**
     * User: chenniang
     * Date: 2019-10-12 14:23
     * @param $value
     * @return array
     * descption:转换图片
     */
    public function getCoverAttr($value){
        $data = transImagesOne([$value],['cover']);
        return !empty($data[0])?$data[0]:[];
    }
    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 栏目列表
     */
    public function columnList($dis,$page = 10){
        $data = $this->where($dis)->status(-1)->order('sort desc')->paginate($page)->toArray();
        return $data;
    }
    /**
     * User: chenniang
     * Date: 2019-10-12 09:54
     * @param $dis
     * @return mixed
     * descption:查询栏目
     */
    public function columnSelect($dis){
        $data = $this->where($dis)->status(-1)->order('sort desc')->select()->toArray();
        return $data;
    }

    /**
     * @param $data
     * @return int|string
     * 添加栏目
     */
    public function columnAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $res = $this->insert($data);
        return $res;
    }
    /**
     * @param $dis
     * @param $data
     * @return AdminCate
     * 编辑栏目
     */
    public function columnUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;
    }
    /**
     * @param $dis
     * @return AdminCate
     * 栏目详情
     */
    public function columnInfo($dis){
        $data = $this->where($dis)->status(-1)->find();
        return !empty($data)?$data->toArray():$data;
    }

    /**
     * User: chenniang
     * Date: 2019-10-14 18:42
     * @return void
     * descption:栏目类型
     */
    public function columnType($uniacid,$id){
        $type = [
            ['key' => 1,'vaule' => '智能报价'],
            ['key' => 2,'vaule' => '免费设计'],
            ['key' => 3,'vaule' => '在建工地'],
            ['key' => 4,'vaule' => '热门活动'],
            ['key' => 5,'vaule' => '大师团队'],
            ['key' => 6,'vaule' => '精品案列'],
            ['key' => 7,'vaule' => '装修攻略'],
            ['key' => 8,'vaule' => '关于我们'],
        ];
        foreach ($type as $key=>$value){
           $dis['type']    = $value['key'];
           $dis['uniacid'] = $uniacid;
           $data  = $this->where($dis)->status(-1)->id($id)->find();
           $type[$key]['is_select'] = !empty($data)?0:1;
        }
        return $type;
    }




}